// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed




export function activate(context: vscode.ExtensionContext) {
    console.log('Congratulations, your extension "bat-symbol" 8888 is now active!');


    const registration = vscode.languages.registerDocumentSymbolProvider(
        {scheme: "file",language: "foo"}, 
        new FooDocumentSymbolProvider());

    context.subscriptions.push(registration);
}


class FooDocumentSymbolProvider implements vscode.DocumentSymbolProvider {


    public provideDocumentSymbols(
            document: vscode.TextDocument,
            token: vscode.CancellationToken): 
            Thenable<vscode.SymbolInformation[]> {

                console.log('create 222');
             return new Promise((resolve, reject) => {
                    let symbols:vscode.SymbolInformation[] = [];

                    console.log(document.lineCount);
                    for (var i = 0; i < document.lineCount; i++) {
                        var line = document.lineAt(i);
                        if (line.text.startsWith(":")) {
                            console.log('add one' + line);
                            symbols.push({
                                name: line.text.substr(1),
                                kind: vscode.SymbolKind.Field,
                                containerName:line.text.substr(1),
                                location: new vscode.Location(document.uri, line.range)
                            })
                        }
                    }
                    resolve(symbols);
        });
    }
}


// this method is called when your extension is deactivated
export function deactivate() {}
